package com.example.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.conf.base.PageResult;
import com.example.conf.base.ResultBase;
import com.example.dto.standard.*;
import com.example.service.StandardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 数据标准目录表 前端控制器
 * </p>
 *
 * @author zhj
 * @since 2023-03-23
 */
@Api(value = "StandardController", tags = "数据标准目录")
@RestController
@RequestMapping("/standard")
public class StandardController {

    @Autowired
    private StandardService standardService;

    @ApiOperation(value = "分页查询标准目录信息")
    @PostMapping("/getStandardList")
    public PageResult<StandardListDto> getPageList(@RequestBody @Validated StandardPageDto standardPageDto) {
        Page<StandardListDto> list = standardService.getPageList(standardPageDto);
        return PageResult.from(list);
    }

    @ApiOperation(value = "单个详情查询")
    @GetMapping("/getDetailData/{id}")
    public ResultBase<StandardDto> getDetailData(@PathVariable("id") Integer id) {
        //通过id查询标准目录详情
        StandardDto standardDto = standardService.queryStandardById(id);
        return ResultBase.successData(standardDto);
    }

    @ApiOperation(value = "新增或修改数据标准目录")
    @PostMapping("/addOrUpdateStandardData")
    public ResultBase<Void> addOrUpdateStandardData(@RequestBody @Validated CreateOrUpdateStandardDto createOrUpdateStandardDto) {
        boolean flag = standardService.addOrUpdateStandardData(createOrUpdateStandardDto);
        if(flag) {
            return ResultBase.success();
        } else {
            return ResultBase.fail();
        }
    }

    @ApiOperation(value = "状态修改")
    @GetMapping("/updateStandardStatus")
    public ResultBase<Void> updateStandardStatus(@RequestBody @Validated UpdateStandardStatusDto updateStandardStatusDto){
        Boolean flag = standardService.updateStandardStatus(updateStandardStatusDto);
        if(flag) {
            return ResultBase.success();
        } else {
            return ResultBase.fail();
        }
    }

    @ApiOperation(value = "逻辑删除标准目录")
    @GetMapping("/delStandard/{id}")
    public ResultBase<Void> delStandard(@PathVariable("id") Integer id) {
        Boolean flag = standardService.delStandard(id);
        if(flag) {
            return ResultBase.success();
        } else {
            return ResultBase.fail();
        }
    }



}

